﻿using IMES.Common.Domain.SirModel;
using IMES.Common.Dtos;
using IMES.Common.Infrastructure;
using MediatR;

namespace GlennQuigmire.API.Application.Commands
{
    public class InboundOrderProductDetailHander : IRequestHandler<InboundOrderProductDetailCommand, ResultT<Product>>
    {

        private readonly IBaseRepositorys<Product> baseRepositorys;
        public InboundOrderProductDetailHander(IBaseRepositorys<Product> baseRepositorys)
        {
            this.baseRepositorys = baseRepositorys;
        }

        /// <summary>
        /// 根据id查询入库单的产品信息
        /// </summary>
        /// <param name="request">根据id查询入库单的产品信息请求对象</param>
        /// <param name="cancellationToken">允许取消异步</param>
        /// <returns>根据id查询入库单的产品信息响应对象</returns>
        public Task<ResultT<Product>> Handle(InboundOrderProductDetailCommand request, CancellationToken cancellationToken)
        {
            var result=  new ResultT<Product>();
            string[] ids = request.ProductIds.Split(',');
            var productIds = new List<Product>();
            foreach (var id in ids)
            {
                var info = baseRepositorys.GetAll().FirstOrDefault(c => c.ProductId ==  Convert.ToInt32( id));
                productIds.Add(info);
            }
            result.Data = productIds;
            return Task.FromResult(result);

        }
    }
}
